﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models.DTO;
using tracker.Models.DAL;
using tracker.Models;

namespace tracker.Controllers
{
    public class HandlerGetAllModelController : Controller
    {
        //
        // GET: /HandlerGetAllModel/
        [CallAjaxFilter]
        public JsonStringResult Index()
        {
            string result = "";
           
            // Get all device type where status = 1 
            List<EDeviceType> list = new List<EDeviceType>();
            list = new DeviceTypeDAL().getByStatus(1);

            // Convert data from EDeviceType to JsonDeviceType (for display purpose)
            List<JsonDeviceType> listjson = new List<JsonDeviceType>();
            foreach (EDeviceType item in list)
            {
                JsonDeviceType ent = new JsonDeviceType();
                ent.ModelIndex = item.DeviceTypeID;
                ent.ModelName = item.DeviceTypeName;
                ent.NotInUse = 1 - item.Status;
                listjson.Add(ent);
            }
            list.Clear();

            result = Utilities.getJsonString(listjson, "", 2);
            return new JsonStringResult(result);
        }

    }

    public class JsonDeviceType
    {
        public int ModelIndex { get; set; }
        public string ModelName { get; set; }
        public int NotInUse { get; set; }
    }
}
